/*
 * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xdlink.component.message.impl.base;

import com.xuexiang.xdlink.component.message.IRequestMessage;

/**
 * 基础的请求消息实体
 *
 * @author xuexiang
 * @since 2018/8/30 下午11:17
 */
public abstract class XRequestMessage extends XMessage implements IRequestMessage {


    /**
     * 构造函数[默认不需要校验和]
     */
    public XRequestMessage() {
        super();
        initRequest();
    }

    /**
     * 构造函数
     *
     * @param isCheck 是否需要校验和
     */
    public XRequestMessage(boolean isCheck) {
        super(isCheck);
        initRequest();
    }

    /**
     * 初始化请求
     */
    private void initRequest() {
        mFrameHead = DEFAULT_FRAME_HEAD;
        setFuncCode(initFuncCode());
        mFrameEnd = DEFAULT_FRAME_END;
    }

    /**
     * @return 初始化请求消息的功能码
     */
    protected abstract byte initFuncCode();

    @Override
    public byte[] toBytes() {
        setContentData(packageData());
        return super.toBytes();
    }
}
